<template>
	<view>
		<view @click="langboxStatus=true">切换站点:{{lang_test}}</view>
		<u-popup :show="langboxStatus" mode="center" @close="langboxStatus=false" round="10">
			 <view class="selectlanguage">
				 <view class="u-padding-10" @click="setBid(1)">中文</view>
				 <u-gap height="10"></u-gap>
				 <view  class="u-padding-10" @click="setBid(71)">English</view>
				 <u-gap height="10"></u-gap>
				 <view  class="u-padding-10" @click="setBid(72)">ภาษาไทย</view>
			 </view>
		</u-popup>
	</view>
</template>

<script>
    import {
    	mapState,
    	mapMutations
    } from 'vuex';
	export default {
		props: {},
		data() {
			return {
				langboxStatus:false,
				name:'站点选择',
				lang_test:''
			};
		},
		computed:{
			...mapState(['siteInfo'])
		},
		created(){
			console.log('siteInfo',this.siteInfo)
			setTimeout(()=>{
			this.lang_test=this.siteInfo.site.lang
			},500)
		},
		methods:{
			...mapMutations(['emptyUserInfo']),
		async setBid(bid){
			let bussdata = {
				bid:bid
			};
			this.$store.commit("set_extConfig",bussdata);

			await this.$store.dispatch("getsiteInfo",{bid:bid}).then(rs=>{
				
				if (rs.bid>0){
					//切换站点后，要退出用户登陆
					//this.emptyUserInfo()
					 this.$i18n.locale = rs.site.lang;
					 uni.setStorageSync('locale',rs.site.lang)
					 console.log(uni.getStorageSync("locale"))
					 this.langboxStatus=!this.langboxStatus;
					const lang = this.$i18n.locale;

					uni.setTabBarItem({
						index: 0,
						text: this.$t('tabBar.tab0'),
					});
					uni.setTabBarItem({
						index: 1,
						text: this.$t('tabBar.tab1'),
					});	 
					uni.setTabBarItem({
						index: 2,
						text: this.$t('tabBar.tab2'),
					});
					uni.setTabBarItem({
						index: 3,
						text: this.$t('tabBar.tab3'),
					});
					setTimeout(()=>{
						this.$tools.goJump('/pages/index/index',{},'','launch')
					},500)
				}
			});
		},
	}
}
</script>

<style lang="scss">
	.selectlanguage{
		padding: 10px 20px;
	}
</style>
